using System;
using System.Collections.Generic;
using System.Linq;



namespace YYS
{
    class Program
    {
        static string[] sp = { "少羽大天狗", "炼狱茨木童子", "稻禾神御馔津", "苍风一目连" };
        static string[] spssr = { "大天狗", "茨木童子", "御馔津", "一目连" };

        static string[] ssr = { "大天狗", "酒吞童子", "荒川之主", "阎魔", "小鹿男", "茨木童子", "青行灯", "妖刀姬", "一目连", "花鸟卷", "辉夜姬", "荒", "彼岸花", "雪童子", "山风", "玉藻前", "御馔津", "面灵气", "鬼切", "八岐大蛇" };

        static string[] sr = {"桃花妖",
                        "雪女",
                        "鬼使白",
                        "鬼使黑",
                        "孟婆",
                        "犬神",
                        "骨女",
                        "鬼女红叶",
                        "跳跳哥哥",
                        "傀儡师",
                        "海坊主",
                        "判官",
                        "凤凰火",
                        "吸血姬",
                        "妖狐",
                        "妖琴师",
                        "食梦貘",
                        "清姬",
                        "镰鼬",
                        "姑获鸟",
                        "二口女",
                        "白狼",
                        "樱花妖",
                        "惠比寿",
                        "络新妇",
                        "般若",
                        "青坊主",
                        "夜叉",
                        "黑童子",
                        "白童子",
                        "烟烟罗",
                        "金鱼姬",
                        "鸩",
                        "以津真天",
                        "匣中少女",
                        "小松丸",
                        "书翁",
                        "百目鬼",
                        "追月神",
                        "日和坊",
                        "薰",
                        "奕",
                        "猫掌柜"};

        static string[] r = {
                        "三尾狐",
                        "座敷童子",
                        "鲤鱼精",
                        "九命猫",
                        "狸猫",
                        "河童",
                        "童男",
                        "童女",
                        "饿鬼",
                        "巫蛊师",
                        "鸦天狗",
                        "食发鬼",
                        "武士之灵",
                        "雨女",
                        "跳跳弟弟",
                        "跳跳妹妹",
                        "兵俑",
                        "丑时之女",
                        "独眼小僧",
                        "铁鼠",
                        "椒图",
                        "管狐",
                        "山兔",
                        "萤草",
                        "蝴蝶精",
                        "山童",
                        "首无",
                        "觉",
                        "青蛙瓷器",
                        "古笼火",
                        "虫师",
                        "小袖之手"};



        static string[] n = { };
        static List<string> SSRList = new List<string>();
        static List<string> SPList = new List<string>();
        static float[] ProbabilityValue = new float[3] { 0.788f, 0.2f, 0.12f };
        static float[] SPProbabilityValue = new float[2] { 0.8f, 0.2f };
        static Random rd = new Random();

        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("《阴阳师》手游对随机抽取类玩法及其概率及结果公布如下：\n" +
                            "1. 神秘的符咒抽到R，SR，SSR阶式神的概率分别为：R卡78.8%，SR卡20%，SSR卡1.2%。\n" +
                            "2.SP式神的概率为单个SSR式神概率的80%"
                           );
                Console.WriteLine("请输入抽卡次数:");
                int cardCout = ImportCheck();
                CreateCard(cardCout);
                while (true)
                {
                    Console.WriteLine("是否继续？");
                    Console.WriteLine(" 0:继续 1:来个十连发");
                    cardCout = ImportCheck();
                    if (cardCout == 1)
                    {
                        CreateCard(10);
                    }
                    else if (cardCout == 0)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 抽卡
        /// </summary>
        /// <param name="cardCout">抽卡数量</param>
        private static void CreateCard(int cardCout)
        {
            int srCount = 0;
            int rCount = 0;
            SSRList.Clear();
            SPList.Clear();
            for (int i = 0; i < cardCout; i++)
            {
                switch (Inder(ProbabilityValue))
                {
                    case 0:
                        CreateCardByR();
                        rCount++;
                        break;
                    case 1:
                        CreateCardBySR();
                        srCount++;
                        break;
                    case 2:
                        CreateCardBySSR();
                        break;
                    default:
                        break;
                }
            }
            Console.WriteLine(string.Format("共抽卡{0}次,抽到SSR式神 {1} 个,抽到SP式神 {2} 个SR式神 {3} 个,R式神 {4} 个", cardCout, SSRList.Count, SPList.Count, srCount, rCount));
            if (SSRList.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.WriteLine("抽到了SSR式神:" + String.Join(",", SSRList.ToArray()));
            }
            if (SPList.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("抽到了SP式神:" + String.Join(",", SPList.ToArray()));
            }
            Console.ResetColor();
        }

        private static int ImportCheck()
        {
            int cardCout;
            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out cardCout))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("请输入有效的数值!");
                }
            }

            return cardCout;
        }

        static void CreateCardBySP()
        {
            int index = rd.Next(0, sp.Length - 1);
            SPList.Add(sp[index]);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("恭喜您抽到SP式神" + sp[index]);
            Console.ResetColor();
        }
        static void CreateCardBySSR()
        {
            int index = rd.Next(0, ssr.Length - 1);
            if (spssr.Contains(ssr[index]))
            {
                int spindex = Inder(SPProbabilityValue);
                switch (spindex)
                {
                    case 0:
                        CreateCardBySP();
                        break;
                    case 1:
                        SSRList.Add(ssr[index]);
                        Console.ForegroundColor = ConsoleColor.DarkMagenta;
                        Console.WriteLine("恭喜您抽到SSR式神" + ssr[index]);
                        Console.ResetColor();
                        break;
                    default:
                        break;
                }
            }
            else
            {
                SSRList.Add(ssr[index]);
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.WriteLine("恭喜您抽到SSR式神" + ssr[index]);
                Console.ResetColor();
            }
        }

        static void CreateCardBySR()
        {

            int index = rd.Next(0, sr.Length - 1);
            Console.WriteLine("抽到SR卡===>>" + sr[index]);
        }

        static void CreateCardByR()
        {

            int index = rd.Next(0, r.Length - 1);
            Console.WriteLine("抽到R卡===>>" + r[index]);
        }




        /// <summary>
        /// 概率
        /// </summary>
        /// <param name="ProbabilityValue"></param>
        /// <returns></returns>
        private static int Inder(float[] ProbabilityValue)
        {
            // float total = 0;
            // //首先计算出概率的总值，用来计算随机范围
            // for (int i = 0; i < ProbabilityValue.Length; i++)
            // {
            //     total += ProbabilityValue[i];
            // }

            double Nob = rd.NextDouble();
            for (int i = 0; i < ProbabilityValue.Length; i++)
            {
                if (Nob < ProbabilityValue[i])
                {
                    return i;
                }
                else
                {
                    Nob -= ProbabilityValue[i];
                }
            }
            return ProbabilityValue.Length - 1;
        }


    }
}
